package yt.kpool;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.ImageView;

public class StartActivity extends AppCompatActivity {

    private int delayMills = 2000;//延迟跳转的时间
    private ImageView imageview;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start);
        start();
    }

    /**
     * 启动页动画 淡出淡入
     */
    private void start() {
        imageview = (ImageView) findViewById(R.id.imageview);
        AlphaAnimation alpha = new AlphaAnimation(0.0f, 1.0f);
        alpha.setDuration(delayMills);
        alpha.setFillAfter(true);
        imageview.setAnimation(alpha);
        alpha.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }
            @Override
            public void onAnimationEnd(Animation animation) {
                imageview.clearAnimation();
                imageview = null;
                startActivity(new Intent(StartActivity.this, MainActivity.class));
                finish();
            }
            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    }

}
